import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter_application_1/components/collapse_row/collapse_row.dart';
import 'package:flutter_application_1/global.dart';

class Index extends StatefulWidget {
  @override
  _IndexState createState() => _IndexState();
}

class _IndexState extends State<Index> with AutomaticKeepAliveClientMixin {
  @override
  bool get wantKeepAlive => true;

  String _currentTime = '';

  final MaterialColor _collapseColor = Colors.blue;

  @override
  void initState() {
    super.initState();
    _currentTime = DateUtil.formatDate(DateTime.now());
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('当前时间：$_currentTime'),
        elevation: 0,
      ),
      body: ListView(
        children: [
          CollapseRow(
            data: CollapseRowData(
              title: '路由',
              list: [
                CollapseRowItemData(
                  title: '路由测试',
                  desc: '使用 fluro 插件实现',
                  onTap: () {
                    Global.routerUtils
                        .navigateTo(
                          context,
                          Global.routeMap.page1,
                        )
                        .then((value) => print(value));
                  },
                ),
              ],
            ),
            color: _collapseColor,
          ),
          CollapseRow(
            data: CollapseRowData(
              title: '状态管理',
              list: [
                CollapseRowItemData(
                  title: '简单计数器',
                  desc: '使用 provider 插件实现',
                  onTap: () {
                    Global.routerUtils.navigateTo(
                      context,
                      Global.routeMap.counterPage,
                    );
                  },
                ),
                CollapseRowItemData(
                  title: '用户信息',
                  desc: '需要依赖的 provider',
                  onTap: () {
                    Global.routerUtils.navigateTo(
                      context,
                      Global.routeMap.userPage,
                    );
                  },
                ),
                CollapseRowItemData(
                  title: '购物车信息',
                  desc: '登录获取用户信息时会同时获取购物车信息',
                  onTap: () {
                    Global.routerUtils.navigateTo(
                      context,
                      Global.routeMap.cartPage,
                    );
                  },
                ),
              ],
            ),
            color: _collapseColor,
          ),
          CollapseRow(
            data: CollapseRowData(
              title: '列表',
              list: [
                CollapseRowItemData(
                  title: '可拖拽列表',
                  desc: 'ReorderableListView、LoadMore',
                  onTap: () {
                    Global.routerUtils.navigateTo(
                      context,
                      Global.routeMap.reorderAbleListPage,
                    );
                  },
                ),
                CollapseRowItemData(
                  title: '普通列表',
                  desc: 'CustomScrollView、SliverAppBar、Grid、Sticky',
                  onTap: () {
                    Global.routerUtils.navigateTo(
                      context,
                      Global.routeMap.customListPage,
                    );
                  },
                ),
                CollapseRowItemData(
                  title: '嵌套列表中简单使用tabbar',
                  desc: 'NestedScrollView、Sticky、TabBar',
                  onTap: () {
                    Global.routerUtils.navigateTo(
                      context,
                      Global.routeMap.nestedScrollTabbar,
                    );
                  },
                ),
                CollapseRowItemData(
                  title: 'tabbar的使用',
                  desc: 'TabBar、自定义indicator、自定义label',
                  onTap: () {
                    Global.routerUtils.navigateTo(
                      context,
                      Global.routeMap.tabbarPage,
                    );
                  },
                ),
                CollapseRowItemData(
                  title: '下拉刷新',
                  desc: 'pull_to_refresh 插件实现',
                  onTap: () {
                    Global.routerUtils.navigateTo(
                      context,
                      Global.routeMap.refreshPage,
                    );
                  },
                ),
                CollapseRowItemData(
                  title: 'PageView',
                  desc: 'PageView简单使用、flutter-swiper插件使用',
                  onTap: () {
                    Global.routerUtils.navigateTo(
                      context,
                      Global.routeMap.pageViewTest,
                    );
                  },
                ),
              ],
            ),
            color: _collapseColor,
          ),
          CollapseRow(
            data: CollapseRowData(
              title: '动画',
              list: [
                CollapseRowItemData(
                  title: '自制折叠面板',
                  desc: 'RotationTransition、AnimatedContainer',
                  onTap: () {
                    Global.routerUtils.navigateTo(
                      context,
                      Global.routeMap.collapseTest,
                    );
                  },
                ),
                CollapseRowItemData(
                  title: '动画',
                  desc: '普通动画、循环动画、交错动画、Marquee',
                  onTap: () {
                    Global.routerUtils.navigateTo(
                      context,
                      Global.routeMap.animateTest,
                    );
                  },
                ),
                CollapseRowItemData(
                  title: 'Hero',
                  desc:
                      'Hero是我们常用的过渡动画，当用户点击一张图片，切换到另一个页面时，这个页面也有此图，那么使用Hero组件就在合适不过了',
                  onTap: () {
                    Global.routerUtils.navigateTo(
                      context,
                      Global.routeMap.heroTest1,
                    );
                  },
                ),
                CollapseRowItemData(
                  title: 'Lottie',
                  desc: 'Lottie 动画控制',
                  onTap: () {
                    Global.routerUtils.navigateTo(
                      context,
                      Global.routeMap.lottieTest,
                    );
                  },
                ),
              ],
            ),
            color: _collapseColor,
          ),
          CollapseRow(
            data: CollapseRowData(
              title: '弹框',
              list: [
                CollapseRowItemData(
                  title: '常用弹框',
                  desc: '简洁提示、底部弹框、密码弹框、日期时间选择、loading、城市地区选择',
                  onTap: () {
                    Global.routerUtils.navigateTo(
                      context,
                      Global.routeMap.commonDialogTest,
                    );
                  },
                ),
                CollapseRowItemData(
                  title: 'Overlay',
                  desc: '可拖动的fab、fab菜单、滚动弹幕',
                  onTap: () {
                    Global.routerUtils.navigateTo(
                      context,
                      Global.routeMap.overlayTest,
                    );
                  },
                ),
                CollapseRowItemData(
                  title: '多列选择器',
                  desc: 'flutter_picker 插件',
                  onTap: () {
                    Global.routerUtils.navigateTo(
                      context,
                      Global.routeMap.flutterPickerTest,
                    );
                  },
                ),
              ],
            ),
            color: _collapseColor,
          ),
          CollapseRow(
            data: CollapseRowData(
              title: '表单',
              list: [
                CollapseRowItemData(
                  title: '简单的表单测试',
                  desc: '随便搞搞',
                  onTap: () {
                    Global.routerUtils.navigateTo(
                      context,
                      Global.routeMap.simpleFormTest,
                    );
                  },
                ),
              ],
            ),
            color: _collapseColor,
          ),
          CollapseRow(
            data: CollapseRowData(
              title: '日常操作',
              list: [
                CollapseRowItemData(
                  title: '网络请求',
                  desc: '使用dio',
                  onTap: () {
                    Global.routerUtils.navigateTo(
                      context,
                      Global.routeMap.requestTest,
                    );
                  },
                ),
                CollapseRowItemData(
                  title: '权限',
                  desc: '简单测试',
                  onTap: () {
                    Global.routerUtils.navigateTo(
                      context,
                      Global.routeMap.permissionTest,
                    );
                  },
                ),
                CollapseRowItemData(
                  title: '通知推送',
                  desc: '暂用极光推送',
                  onTap: () {
                    Global.routerUtils.navigateTo(
                      context,
                      Global.routeMap.notificationPushTest,
                    );
                  },
                ),
                CollapseRowItemData(
                  title: '定位',
                  desc: '暂用高德地图',
                  onTap: () {
                    Global.routerUtils.navigateTo(
                      context,
                      Global.routeMap.selectLocation,
                    );
                  },
                ),
              ],
            ),
            color: _collapseColor,
          ),
          CollapseRow(
            data: CollapseRowData(
              title: '随便做做',
              list: [
                CollapseRowItemData(
                  title: '一元抓娃娃首页 tabbar',
                  desc: '静态页面',
                  onTap: () {
                    Global.routerUtils.navigateTo(
                      context,
                      Global.routeMap.prizeClawIndex,
                    );
                  },
                ),
                CollapseRowItemData(
                  title: '简单的自定义安卓插件',
                  desc: '目前只做了安卓',
                  onTap: () {
                    Global.routerUtils.navigateTo(
                      context,
                      Global.routeMap.dynamicPlugins,
                    );
                  },
                ),
              ],
            ),
            color: _collapseColor,
          ),
        ],
      ),
    );
  }
}
